<?php
/**
 * @file
 *   Overrides save functionality from FieldCollectionItemEntity in order to
 *   avoid exceptions when deploying a field_collection entity before its host
 *   entity exists.
 */
class UUIDFieldCollectionItemEntity extends FieldCollectionItemEntity {
  public function save($skip_host_save = FALSE) {
    if (isset($this->hostEntity) || empty($this->__uuid_universalized)) {
      // If we have a host entity or this entity has not been universalized by
      // deploy. $this->__uuid_universalised is set in
      // field_collection_entity_uuid_load().
      parent::save($skip_host_save);
    }
    else {
      // If there is no host entity, we may be receiving it from deploy
      // so save the item directly (and force revision id to match item id)
      $this->revision = TRUE;
      entity_get_controller($this->entityType)->save($this);
    }
  }
}
